﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace NetTopologySuite.Geometries.Utilities
{
	public static class GeometryExtracter
	{
		public static IList<IGeometry> Extract<T>(IGeometry geom, IList<IGeometry> list) where T : class, IGeometry
		{
			if (geom is T)
			{
				list.Add(geom as T);
			}
			else if (geom is IGeometryCollection)
			{
				geom.Apply(new GeometryExtracter<T>(list));
			}
			return list;
		}

		public static IList<IGeometry> Extract<T>(IGeometry geom) where T : class, IGeometry
		{
			return GeometryExtracter.Extract<T>(geom, new List<IGeometry>());
		}
	}
}
